import { IPSDEGrid } from '../../control/grid/ipsdegrid';
import { LogUtil } from '../../core';
import { IPSModelObject } from '../../ipsmodel-object';
import { PSModelServiceProxyImpl } from '../../psmodel-service-proxy-impl';

/**
 * 全局默认通用代理
 *
 * @author chitanda
 * @date 2021-06-08 20:06:55
 * @export
 * @class PSDEGridServiceProxy
 * @extends {PSModelServiceProxyImpl}
 */
export class PSDEGridServiceProxy extends PSModelServiceProxyImpl {
  getPSModel4(
    relatedPSModelObject: IPSModelObject,
    cls: string,
    objNode: any,
    strTag: string,
  ): IPSModelObject {
    switch (strTag) {
      case 'getAggPSAppDEDataSet':
        return this.getAggPSAppDEDataSet(
          relatedPSModelObject as IPSDEGrid,
          objNode,
        );
    }
    return this.getRealPSModelService().getPSModel4(
      relatedPSModelObject,
      cls,
      objNode,
      strTag,
    );
  }

  getAggPSAppDEDataSet(relatedPSModelObject: IPSDEGrid, obj: any): any {
    const entity = relatedPSModelObject.getAggPSAppDataEntity();
    if (entity && entity.isFill) {
      return entity.findPSAppDEDataSet(obj);
    } else {
      LogUtil.error(
        'getAggPSAppDataEntity 视图不存在或未填充，无法查找 getAggPSAppDEDataSet 数据集。',
        relatedPSModelObject,
      );
    }
    return null;
  }
}
